package com.example.alipay.controller;

import cn.org.bjca.seal.esspdf.client.ClientConstant;
import cn.org.bjca.seal.esspdf.client.enumeration.EnumFontFamily;
import cn.org.bjca.seal.esspdf.client.enumeration.TimeTagFromat;
import cn.org.bjca.seal.esspdf.client.message.*;
import cn.org.bjca.seal.esspdf.client.tools.AnySignClientTool;
import cn.org.bjca.seal.esspdf.client.utils.ClientUtil;
import com.example.alipay.config.utils.R;
import org.apache.catalina.SessionIdGenerator;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Decoder;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;

@RestController
public class PdfController {
    static AnySignClientTool anySignClientTool = null;

    static private String resourcesPath;
    static String testPdfFilePath;
    static String testSignedPdfFilePath;
    static String testImageFilePath;
    ResponseEntity responseEntity = null;
    static  String basepath = null;
    static  String resourcepath = null;

    static {
        File directory = new File("../dsvs/src/main/resources");

        try {
            basepath = directory.getCanonicalPath();
            resourcepath =basepath+"\\";
            System.out.println("根本路径："+resourcepath);
        } catch (IOException e) {
            e.printStackTrace();
        }


        String ip = "223.70.139.221";
        int port = 8888;
        try {
            anySignClientTool = new AnySignClientTool(ip, port);
            if (anySignClientTool != null) {
                System.out.println("连接服务成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        //连接服务器超时时间，单位是毫秒，默认为5秒，当前为50秒
        anySignClientTool.setTimeout(50000);//连接超时时间设置
        anySignClientTool.setRespTimeout(50000);//响应超时时间

        testPdfFilePath = resourcesPath + "pdf" + File.separator + "test.pdf";
        testSignedPdfFilePath = resourcesPath + "pdf" + File.separator + "signedPDF.pdf";
        testImageFilePath = resourcesPath + "image" + File.separator + "test.gif";

    }

    public static void main(String[] args) throws Exception{



    }


    /**
     * 生成文件hash
     * @param file
     * @param ukeyCert
     * @param sealImg
     * @param sealImgWide
     * @param sealImgHigh
     * @param moveType
     * @param keyword
     * @param searchOrder
     * @param HeightMoveSize
     * @param MoveSize
     * @return
     * @throws Exception
     */
    @RequestMapping("/getPDFHashByKeyword")
    public R getPDFHash(      @RequestParam("file") MultipartFile file,
                              @RequestParam("ukeyCert") String ukeyCert,
                              @RequestParam("sealImg") String sealImg,
                              @RequestParam("sealImgWide") String sealImgWide,
                              @RequestParam("sealImgHigh") String sealImgHigh,
                              @RequestParam("moveType") String moveType,
                              @RequestParam("keyword") String keyword,
                              @RequestParam("searchOrder") String searchOrder,
                              @RequestParam("HeightMoveSize") String HeightMoveSize,
                              @RequestParam("MoveSize") String MoveSize  ) throws Exception {
        System.out.println(ukeyCert);
        System.out.println(sealImg);
        List<ClientSignMessage> clientSignMessages = new ArrayList<ClientSignMessage>();
        //pdf 字节数组
        byte[] pdfBty = file.getBytes();
        //印章移动类型 1:重叠、2: 居下、3:居右,默认居右
        ClientSignMessage clientSignMessage = new ClientSignMessage();
//页码设置
//        RectangleBean r=new RectangleBean();
//        r.setPageNo(2);
//        clientSignMessage.setRectangleBean(r);
        //1，关键字定位；2，坐标定位； 3，骑缝章
        clientSignMessage.setRuleType("1");

        clientSignMessage.setKeyword(keyword);
//移动类型 1:重叠、2: 居下、3:居右,默认居右
        clientSignMessage.setMoveType(moveType);
        clientSignMessage.setSearchOrder(searchOrder);
        clientSignMessage.setPdfBty(pdfBty);
        clientSignMessage.setFileUniqueId("123456654321");
        clientSignMessage.setHeightMoveSize(Integer.valueOf(HeightMoveSize));
        clientSignMessage.setMoveSize(Integer.valueOf(MoveSize));
        clientSignMessages.add(clientSignMessage);
        ChannelMessage message = anySignClientTool.genClientSignDigest(clientSignMessages, ukeyCert, sealImg,  Float.parseFloat (sealImgWide) ,
                Float.parseFloat (sealImgHigh) );
        System.out.println("状态码：" + message.getStatusCode());
        System.out.println("状态信息：" + message.getStatusInfo());
        System.out.println("摘要数据：" + new String(message.getBody()));
        if(message.getStatusCode().equals("200")){
            List<String> arraylist=new ArrayList<>();
            arraylist.add(message.getStatusCode());
            arraylist.add(message.getStatusInfo());
            arraylist.add(new String(message.getBody()));
            HashMap<String,Object> map=new HashMap<>();
            map.put("statecode",arraylist);
            map.put("message",message.getStatusCode());
            return  R.ok().put("map",map);
        }
        else {
            return  R.error();
        }
    }


    @RequestMapping("/getPDFHashByKeywordgetExtendedInformation")
    public R getPDFHashByKeywordgetExtendedInformation(      @RequestParam("file") MultipartFile file,
                              @RequestParam("ukeyCert") String ukeyCert,
                              @RequestParam("sealImg") String sealImg,
                              @RequestParam("sealImgWide") String sealImgWide,
                              @RequestParam("sealImgHigh") String sealImgHigh,
                              @RequestParam("moveType") String moveType,
                              @RequestParam("keyword") String keyword,
                              @RequestParam("searchOrder") String searchOrder,
                              @RequestParam("HeightMoveSize") String HeightMoveSize,
                              @RequestParam("ExtendedInformation") String ExtendedInformation,
                              @RequestParam("MoveSize") String MoveSize  ) throws Exception {
        List<ClientSignMessage> clientSignMessages = new ArrayList<ClientSignMessage>();
        //pdf 字节数组
        byte[] pdfBty = file.getBytes();
        //印章移动类型 1:重叠、2: 居下、3:居右,默认居右
        ClientSignMessage clientSignMessage = new ClientSignMessage();
//页码设置
//        RectangleBean r=new RectangleBean();
//        r.setPageNo(2);
//        clientSignMessage.setRectangleBean(r);
        //1，关键字定位；2，坐标定位； 3，骑缝章
        clientSignMessage.setRuleType("1");

        clientSignMessage.setKeyword(keyword);
//移动类型 1:重叠、2: 居下、3:居右,默认居右
        clientSignMessage.setMoveType(moveType);
        clientSignMessage.setSearchOrder(searchOrder);
        clientSignMessage.setPdfBty(pdfBty);
        clientSignMessage.setFileUniqueId("521000123");
        clientSignMessage.setHeightMoveSize(Integer.valueOf(HeightMoveSize));
        clientSignMessage.setMoveSize(Integer.valueOf(MoveSize));
        clientSignMessages.add(clientSignMessage);
//拓展信息
        ExtentionBean extBean=new ExtentionBean();
        extBean.setOnSealText(ExtendedInformation);
        extBean.setFontFamily(EnumFontFamily.FONTFAMILY_1.name());
        extBean.setFontSize("12");
        extBean.setFontColor("#FF0000");
// setTimeFromat 参数在 sealImg=”0”的时候设置日期格式，生成默认的日期图片签章使用  ;也就是在没图片的时候，即0
        extBean.setTimeFromat(TimeTagFromat.CHINESE_FORMAT.name());

        ChannelMessage message = anySignClientTool.genClientSignDigest(clientSignMessages, ukeyCert, sealImg,  Float.parseFloat (sealImgWide) ,
                Float.parseFloat (sealImgHigh),extBean);
        System.out.println("状态码：" + message.getStatusCode());
        System.out.println("状态信息：" + message.getStatusInfo());
        System.out.println("摘要数据：" + new String(message.getBody()));


        if(message.getStatusCode().equals("200")){
            List<String> arraylist=new ArrayList<>();
            arraylist.add(message.getStatusCode());
            arraylist.add(message.getStatusInfo());
            arraylist.add(new String(message.getBody()));
            HashMap<String,Object> map=new HashMap<>();
            map.put("statecode",arraylist);
            map.put("message",message.getStatusCode());
            return  R.ok().put("map",map);
        }
        else {
            return  R.error();
        }
    }

    /**
     * 代理签章接口
     * @param requestBody
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/ProxyClientSignature", method = RequestMethod.POST)
    public R ProxyClientSignature(@RequestBody Map<String, Object> requestBody ) throws Exception {
        String clientSignaturJson = (String) requestBody.get("ClientSignaturJson");
        System.out.println(clientSignaturJson);
        ChannelMessage message = anySignClientTool.genClientSign(clientSignaturJson);
        System.out.println("状态码："+message.getStatusCode());
        System.out.println("状态信息："+message.getStatusInfo());
        if(message.getStatusCode().equals("200")){
            ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\生成代理签章.pdf"),message.getBody());
            return R.ok();
        }  else {
            return R.error(message.getStatusInfo());
        }

    }

    /**
     * PDF插入条形码
     * @param file
     * @param barcoderuleNumber
     * @param contents
     * @return
     * @throws Exception
     */
    @RequestMapping("/creatBaecodeAndIntoPdf")
    public R creatBaecodeAndIntoPdf(@RequestParam("file") MultipartFile file,
                              @RequestParam("barcoderuleNumber") String barcoderuleNumber,
                              @RequestParam("contents") String contents) throws Exception {
        String content = contents.getBytes(Charset.forName("UTF-8")).toString();
        ChannelMessage message =anySignClientTool.genBarcode(barcoderuleNumber, contents, file.getBytes());
        System.out.println("状态码：" + message.getStatusCode());
        System.out.println("状态信息："+message.getStatusInfo());
        if(message.getStatusCode().equals("200")){
            ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\PDF插入条形码.pdf"), message.getBody());
            return R.ok();
        }  else {
            return R.error(message.getStatusInfo());
        }

    }



    /**
     * Word文档转换PDF插入条形码
     * @param file
     * @param barcoderuleNumber
     * @param signSealRuleNum
     * @param contents
     * @return
     * @throws Exception
     */
    @RequestMapping("/wordtoPDFandSeal")
    public R wordtoPDFandSeal(@RequestParam("file") MultipartFile file,
                                     @RequestParam("barcoderuleNumber") String barcoderuleNumber,
                              @RequestParam("signSealRuleNum") String signSealRuleNum,
                              @RequestParam("contents") String contents) throws Exception {

        ChannelMessage message = anySignClientTool.genBarcodeAndSignByWord(barcoderuleNumber, signSealRuleNum, contents,
                file.getBytes());
        System.out.println("状态码："+message.getStatusCode());
        System.out.println("状态信息："+message.getStatusInfo());
        ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\Word文档转换PDF插入条形码.pdf"),message.getBody());
        if(message.getStatusCode().equals("200")){
            return R.ok();
        }  else {
            return R.error(message.getStatusInfo());
        }

    }

    @RequestMapping("/wordtoPDFandSeal2")
    public R wordtoPDFandSeal2(@RequestParam("file") MultipartFile file,
                              @RequestParam("signSealRuleNum") String signSealRuleNum) throws Exception {

        ChannelMessage message = anySignClientTool.pdfSignByWord(signSealRuleNum,file.getBytes());
        System.out.println("状态码："+message.getStatusCode());
        System.out.println("状态信息："+message.getStatusInfo());
        ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\Word文档转换PDF签章.pdf"),message.getBody());
        if(message.getStatusCode().equals("200")){
            return R.ok();
        }  else {
            return R.error(message.getStatusInfo());
        }

    }

    /**
     * 根据模板产生签名域
     * @param file
     * @param signplacenumber
     * @return
     * @throws Exception
     */
    @RequestMapping("/byMoudelCreateSignPlace")
    public R byMoudelCreateSignPlace(@RequestParam("file") MultipartFile file,
                          @RequestParam("signplacenumber") String signplacenumber) throws Exception {
        String ruleNum =signplacenumber;//签名域规则编号

        byte[] xml = file.getBytes();
        ChannelMessage message = anySignClientTool.genSignFieldByXML(ruleNum, xml);
        System.out.println("状态码："+message.getStatusCode());
        System.out.println("状态信息："+message.getStatusInfo());
        ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\模板产生签名域.pdf"),message.getBody());
        if(message.getStatusCode().equals("200")){
            return R.ok();
        }  else {
            return R.error(message.getStatusInfo());
        }

    }

    /**
     * 产生空签名域
     * @param file
     * @param signplacenumber
     * @return
     * @throws Exception
     */
    @RequestMapping("/CreateNullSignPlace")
    public R CreateNullSignPlace(@RequestParam("file") MultipartFile file,
                                     @RequestParam("signplacenumber") String signplacenumber) throws Exception {
        String ruleNum =signplacenumber;//签名域规则编号

        byte[] pdfBty = file.getBytes();
        ChannelMessage message = anySignClientTool.genSignField(ruleNum, "", pdfBty);
        System.out.println("状态码："+message.getStatusCode());
        System.out.println("状态信息："+message.getStatusInfo());
        ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\空签名域.pdf"),message.getBody());
        if(message.getStatusCode().equals("200")){
            return R.ok();
        }  else {
            return R.error(message.getStatusInfo());
        }

    }

    //3.1.15.1.1.	客户端传所有签章参数基于坐标定位签章
    @RequestMapping("/poistionpdf")
    public R testFileSignByParam2(@RequestParam("file") MultipartFile file, @RequestParam("Server_seal_number") String serverSealNumber,
                                  @RequestParam("Signature_policy_number") String signaturePolicyNumber,
                                  @RequestParam("Timestamp_policy_number") String timestampPolicyNumber,
                                  @RequestParam("pageno") String pageno,
                                  @RequestParam("top") String top,
                                  @RequestParam("bottom") String bottom,
                                  @RequestParam("left") String left,
                                  @RequestParam("right") String right,
                                  @RequestParam("pageStart") String pageStart,
                                  @RequestParam("pageEnd") String pageEnd
    ) throws Exception {

        System.out.println("服务器印章编号:" + serverSealNumber);
        System.out.println("签名策略编号:" + signaturePolicyNumber);
        System.out.println("时间戳签名策略:" + timestampPolicyNumber);
        System.out.println("file:" + file.getBytes());


        List<ClientSignMessage> messages = new ArrayList<ClientSignMessage>();
        ClientSignMessage clientSignMessage = new ClientSignMessage();
        //pdf字节数组
        byte[] fileBty = file.getBytes();
        List<SignRuleBean> signRuleBeanList = new ArrayList<SignRuleBean>();
        SignRuleBean signRuleBean1 = new SignRuleBean();
        String tssCertSN1 = timestampPolicyNumber;//时间戳签名策略
        String certSN1 = signaturePolicyNumber;//签名策略编号
        String serverSealNum1 = serverSealNumber;//服务器印章编号

        RectangleBean rectangleBean1 = new RectangleBean();
        rectangleBean1.setTssCertSN(tssCertSN1);
        rectangleBean1.setServerSealNum(serverSealNum1);
        rectangleBean1.setCertSN(certSN1);
        //设置页码
        if(!pageno.equals("")){
            rectangleBean1.setPageNo(Integer.parseInt(pageno));
        }
//        rectangleBean1.setPageNo(6);
        //设置签章位置
        rectangleBean1.setLeft(Float.parseFloat(left));
        rectangleBean1.setTop(Float.parseFloat(top));
        rectangleBean1.setRight(Float.parseFloat(right));
        rectangleBean1.setBottom(Float.parseFloat(bottom));
        //开始页  结束页
        if(!pageStart.equals("") && !pageEnd.equals("")){
            rectangleBean1.setSignPages((new int[]{Integer.parseInt(pageStart), Integer.parseInt(pageEnd)}));
        }


        signRuleBean1.setRectangleBean(rectangleBean1);//坐标定位对象
        signRuleBeanList.add(signRuleBean1);

        SignRuleBean signRuleBean2=new SignRuleBean();
        String tssCertSN2 ="1820FC8AA017784";//时间戳签名策略
        String certSN2 = "5CEB9AA24A242D6C";//签名策略编号
        String serverSealNum2 = "619F6EF2AD6B4FEB";//服务器印章编号
        RectangleBean rectangleBean2 = new RectangleBean();
        rectangleBean2.setTssCertSN(tssCertSN2);
        rectangleBean2.setServerSealNum(serverSealNum2);
        rectangleBean2.setCertSN(certSN2);
        rectangleBean2.setPageNo(1);
        rectangleBean2.setLeft(100f);
        rectangleBean2.setTop(100f);
        rectangleBean2.setRight(100f);
        rectangleBean2.setBottom(100f);
        signRuleBean2.setRectangleBean(rectangleBean2);//坐标定位对象
        signRuleBeanList.add(signRuleBean2);

        clientSignMessage.setFileBty(fileBty);//签章文件
        clientSignMessage.setFileUniqueId("1111");
        clientSignMessage.setEntityType(ENTITYType.PDF);//签章文件类型(签章文件类型不设置默认签章文件类型为PDF)
        clientSignMessage.setSignRuleBeanList(signRuleBeanList);//签章参数集合
        messages.add(clientSignMessage);
        ChannelMessage message = anySignClientTool.pdfBatchSignCByParam(messages);
        System.out.println("状态码：" + message.getStatusCode());
        System.out.println("状态信息：" + message.getStatusInfo());

        if ("200".equals(message.getStatusCode())) { // 成功，获取签章文件
            List<ClientSignBean> signBeanList = message.getClientSignList();
            System.out.println("签章结果列表：");
            for (ClientSignBean beanObj : signBeanList) {
                System.out.println("签章流水:" + beanObj.getSignUniqueId() + "##状态码：" + beanObj.getStatusCode() + "##状态信息：" + beanObj.getStatusInfo());
                if ("200".equals(beanObj.getStatusCode())) {

                    ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\result.pdf"), beanObj.getPdfBty());
                    return R.ok();
                } else {
                    return R.error(beanObj.getStatusInfo());
                }

            }

        }

        return null;
    }


    @RequestMapping("/keywordpdf")
    public R testFileSignByParam1(@RequestParam("file") MultipartFile file, @RequestParam("keyword") String keyword,
                                  @RequestParam("KeywordNum") String KeywordNum,
                                  @RequestParam("moveType") String moveType,
                                  @RequestParam("pageno") String pageno,
                                  @RequestParam("MoveSize") String MoveSize,
                                  @RequestParam("HeightMoveSize") String HeightMoveSize,
                                  @RequestParam("IsPrint") String IsPrint,
                                  @RequestParam("SearchOrder") String SearchOrder,
                                     @RequestParam("Signature_policy_number") String signaturePolicyNumber,
                                     @RequestParam("Timestamp_policy_number") String timestampPolicyNumber
    ) throws Exception {
        List<ClientSignMessage> messages = new ArrayList<ClientSignMessage>();
        ClientSignMessage clientSignMessage = new ClientSignMessage();
        //pdf 字节数组
        byte[] fileBty =file.getBytes();
        //image 字节数组
        byte[] imageBty1 = ClientUtil.readFileToByteArray(new File(resourcepath+"Rpdf\\2.gif"));
        List<SignRuleBean> signRuleBeanList = new ArrayList<SignRuleBean>();
        SignRuleBean signRuleBean=new SignRuleBean();
        String tssCertSN =timestampPolicyNumber;//时间戳签名策略
        String certSN = signaturePolicyNumber;//签名策略编号
        String sealImg1 = Base64.getEncoder().encodeToString(imageBty1);
        KeywordBean bean = new KeywordBean();
        bean.setTssCertSN(tssCertSN);
        bean.setCertSN(certSN);
        bean.setSealImg(sealImg1);
        bean.setKeyword(keyword);
        bean.setPageNo(Integer.parseInt(pageno));
        bean.setSearchOrder(SearchOrder); // 检索顺序 0:全部、 1:正序、2:倒序
        bean.setKeywordNum(KeywordNum);//第几个关键字
        bean.setMoveType(moveType);
        if(IsPrint.equals("0")){
            bean.setIsPrint("false");//是否打印
        }
        if(IsPrint.equals("1")){
            bean.setIsPrint("true");//是否打印
        }
        //子左右偏移量
        bean.setMoveSize(Integer.valueOf(MoveSize));
        //上下偏移量
        bean.setHeightMoveSize(Integer.valueOf(HeightMoveSize));
        signRuleBean.setKeywordBean(bean);//关键字定位对象
        signRuleBeanList.add(signRuleBean);


        //image 字节数组
        byte[] imageBty2 = ClientUtil.readFileToByteArray(new File(resourcepath+"Rpdf\\QQ.gif"));
        SignRuleBean signRuleBean2=new SignRuleBean();
        String tssCertSN2 ="1820FC8AA017784";//时间戳签名策略
        String certSN2 = "64F9EEA6ABB10702";//签名策略编号
        String sealImg2 = Base64.getEncoder().encodeToString(imageBty2);
        KeywordBean bean2 = new KeywordBean();
        bean2.setTssCertSN(tssCertSN2);
        bean2.setCertSN(certSN2);
        bean2.setSealImg(sealImg2);
        bean2.setKeyword("数字认证");
        bean2.setSearchOrder("0"); // 检索顺序 0:全部、 1:正序、2:倒序
        bean2.setKeywordNum("1");
        bean2.setMoveType("1");
        bean2.setIsPrint("false");
        bean2.setMoveSize(0);
        bean2.setHeightMoveSize(0);
        signRuleBean2.setKeywordBean(bean2);//关键字定位对象
        signRuleBeanList.add(signRuleBean2);
//

        clientSignMessage.setFileBty(fileBty);//签章文件
        clientSignMessage.setFileUniqueId("1111");
        clientSignMessage.setEntityType(ENTITYType.PDF);//签章文件类型(签章文件类型不设置默认签章文件类型为 PDF)
        clientSignMessage.setSignRuleBeanList(signRuleBeanList);//签章参数集合
        messages.add(clientSignMessage);
        ChannelMessage message = anySignClientTool.pdfBatchSignCByParam(messages);
        System.out.println("状态码：" + message.getStatusCode());
        System.out.println("状态信息："+message.getStatusInfo());
        if("200".equals(message.getStatusCode())){ // 成功，获取签章文件
            List<ClientSignBean> signBeanList = message.getClientSignList();
            System.out.println("签章结果列表：");
            for (ClientSignBean beanObj : signBeanList) {
                System.out.println("签章流水:"+beanObj.getSignUniqueId()+"##状态码："+beanObj.getStatusCode()+"##状态信息："+beanObj.getStatusInfo());
                if("200".equals(beanObj.getStatusCode())){
                    ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\result2.pdf"),
                            beanObj.getPdfBty());
                    return R.ok();
                }
                else {
                    return R.error(beanObj.getStatusInfo());
                }
            }
        }
        return null;
    }

    /**
     * 基于服务器印章编号及坐标定位的 PDF 签章门面
     * @param file
     * @param serverSealNumber

     * @param timestampPolicyNumber
     * @param pageno
     * @param top
     * @param bottom
     * @param left
     * @param right
     * @param pageStart
     * @param pageEnd
     * @return
     * @throws Exception
     */
    @RequestMapping("/BaseServeSealnumAndpoistion")
    public R testFileSignByParam3(@RequestParam("file") MultipartFile file, @RequestParam("Server_seal_number") String serverSealNumber,

                                  @RequestParam("Timestamp_policy_number") String timestampPolicyNumber,
                                  @RequestParam("pageno") String pageno,
                                  @RequestParam("top") String top,
                                  @RequestParam("bottom") String bottom,
                                  @RequestParam("left") String left,
                                  @RequestParam("right") String right,
                                  @RequestParam("pageStart") String pageStart,
                                  @RequestParam("pageEnd") String pageEnd
    ) throws Exception {

        System.out.println("服务器印章编号:" + serverSealNumber);

        System.out.println("时间戳签名策略:" + timestampPolicyNumber);
        System.out.println("file:" + file.getBytes());


        List<ClientSignMessage> messages = new ArrayList<ClientSignMessage>();
        ClientSignMessage clientSignMessage = new ClientSignMessage();
        //pdf字节数组
        byte[] fileBty = file.getBytes();
        List<SignRuleBean> signRuleBeanList = new ArrayList<SignRuleBean>();
        SignRuleBean signRuleBean1 = new SignRuleBean();
        String tssCertSN1 = timestampPolicyNumber;//时间戳签名策略

        String serverSealNum1 = serverSealNumber;//服务器印章编号

        RectangleBean rectangleBean1 = new RectangleBean();
        rectangleBean1.setTssCertSN(tssCertSN1);
        rectangleBean1.setServerSealNum(serverSealNum1);

        //设置页码
        if(!pageno.equals("")){
            rectangleBean1.setPageNo(Integer.parseInt(pageno));
        }
//        rectangleBean1.setPageNo(6);
        //设置签章位置
        rectangleBean1.setLeft(Float.parseFloat(left));
        rectangleBean1.setTop(Float.parseFloat(top));
        rectangleBean1.setRight(Float.parseFloat(right));
        rectangleBean1.setBottom(Float.parseFloat(bottom));
        //开始页  结束页
        if(!pageStart.equals("") && !pageEnd.equals("")){
            rectangleBean1.setSignPages((new int[]{Integer.parseInt(pageStart), Integer.parseInt(pageEnd)}));
        }


        signRuleBean1.setRectangleBean(rectangleBean1);//坐标定位对象
        signRuleBeanList.add(signRuleBean1);

        SignRuleBean signRuleBean2=new SignRuleBean();
        String tssCertSN2 ="1820FC8AA017784";//时间戳签名策略

        String serverSealNum2 = "619F6EF2AD6B4FEB";//服务器印章编号
        RectangleBean rectangleBean2 = new RectangleBean();
        rectangleBean2.setTssCertSN(tssCertSN2);
        rectangleBean2.setServerSealNum(serverSealNum2);

        rectangleBean2.setPageNo(1);
        rectangleBean2.setLeft(100f);
        rectangleBean2.setTop(100f);
        rectangleBean2.setRight(100f);
        rectangleBean2.setBottom(100f);
        signRuleBean2.setRectangleBean(rectangleBean2);//坐标定位对象
        signRuleBeanList.add(signRuleBean2);

        clientSignMessage.setFileBty(fileBty);//签章文件
        clientSignMessage.setFileUniqueId("1111");
        clientSignMessage.setEntityType(ENTITYType.PDF);//签章文件类型(签章文件类型不设置默认签章文件类型为PDF)
        clientSignMessage.setSignRuleBeanList(signRuleBeanList);//签章参数集合
        messages.add(clientSignMessage);
        ChannelMessage message = anySignClientTool.pdfBatchSignCByParam(messages);
        System.out.println("状态码：" + message.getStatusCode());
        System.out.println("状态信息：" + message.getStatusInfo());

        if ("200".equals(message.getStatusCode())) { // 成功，获取签章文件
            List<ClientSignBean> signBeanList = message.getClientSignList();
            System.out.println("签章结果列表：");
            for (ClientSignBean beanObj : signBeanList) {
                System.out.println("签章流水:" + beanObj.getSignUniqueId() + "##状态码：" + beanObj.getStatusCode() + "##状态信息：" + beanObj.getStatusInfo());
                if ("200".equals(beanObj.getStatusCode())) {

                    ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\result3.pdf"), beanObj.getPdfBty());
                    return R.ok();
                } else {
                    return R.error(beanObj.getStatusInfo());
                }

            }

        }

        return null;
    }


    @RequestMapping("/BaseServeSealnumAndkeywordpdf")
    public R testFileSignByParam4(@RequestParam("file") MultipartFile file,
                                  @RequestParam("Server_seal_number") String serverSealNumber,
                                  @RequestParam("Timestamp_policy_number") String timestampPolicyNumber,
                                  @RequestParam("keyword") String keyword,
                                  @RequestParam("KeywordNum") String KeywordNum,
                                  @RequestParam("moveType") String moveType,
                                  @RequestParam("pageno") String pageno,
                                  @RequestParam("MoveSize") String MoveSize,
                                  @RequestParam("HeightMoveSize") String HeightMoveSize,
                                  @RequestParam("IsPrint") String IsPrint,
                                  @RequestParam("SearchOrder") String SearchOrder


    ) throws Exception {
        List<ClientSignMessage> messages = new ArrayList<ClientSignMessage>();
        ClientSignMessage clientSignMessage = new ClientSignMessage();
        //pdf 字节数组
        byte[] fileBty =file.getBytes();
        //image 字节数组

        List<SignRuleBean> signRuleBeanList = new ArrayList<SignRuleBean>();
        SignRuleBean signRuleBean=new SignRuleBean();
        String tssCertSN =timestampPolicyNumber;//时间戳签名策略

        String serveSeal = serverSealNumber;//签名策略编号

        KeywordBean bean = new KeywordBean();

        bean.setTssCertSN(tssCertSN);
        bean.setServerSealNum(serveSeal);

        bean.setKeyword(keyword);
        bean.setPageNo(Integer.parseInt(pageno));
        bean.setSearchOrder(SearchOrder); // 检索顺序 0:全部、 1:正序、2:倒序
        bean.setKeywordNum(KeywordNum);//第几个关键字
        bean.setMoveType(moveType);
        if(IsPrint.equals("0")){
            bean.setIsPrint("false");//是否打印
        }
        if(IsPrint.equals("1")){
            bean.setIsPrint("true");//是否打印
        }
        //子左右偏移量
        bean.setMoveSize(Integer.valueOf(MoveSize));
        //上下偏移量
        bean.setHeightMoveSize(Integer.valueOf(HeightMoveSize));
        signRuleBean.setKeywordBean(bean);//关键字定位对象
        signRuleBeanList.add(signRuleBean);



        SignRuleBean signRuleBean2=new SignRuleBean();
        String tssCertSN2 ="1820FC8AA017784";//时间戳签名策略
        String serveSeal2 = "60465486508A6DE5";//服务器印章编号

        KeywordBean bean2 = new KeywordBean();
        bean2.setTssCertSN(tssCertSN2);
        bean2.setServerSealNum(serveSeal2);

        bean2.setKeyword("数字认证");
        bean2.setSearchOrder("0"); // 检索顺序 0:全部、 1:正序、2:倒序
        bean2.setKeywordNum("1");
        bean2.setMoveType("1");
        bean2.setIsPrint("false");
        bean2.setMoveSize(0);
        bean2.setHeightMoveSize(0);
        signRuleBean2.setKeywordBean(bean2);//关键字定位对象
        signRuleBeanList.add(signRuleBean2);
//

        clientSignMessage.setFileBty(fileBty);//签章文件
        clientSignMessage.setFileUniqueId("1111");
        clientSignMessage.setEntityType(ENTITYType.PDF);//签章文件类型(签章文件类型不设置默认签章文件类型为 PDF)
        clientSignMessage.setSignRuleBeanList(signRuleBeanList);//签章参数集合
        messages.add(clientSignMessage);
        ChannelMessage message = anySignClientTool.pdfBatchSignCByParam(messages);
        System.out.println("状态码：" + message.getStatusCode());
        System.out.println("状态信息："+message.getStatusInfo());
        if("200".equals(message.getStatusCode())){ // 成功，获取签章文件
            List<ClientSignBean> signBeanList = message.getClientSignList();
            System.out.println("签章结果列表：");
            for (ClientSignBean beanObj : signBeanList) {
                System.out.println("签章流水:"+beanObj.getSignUniqueId()+"##状态码："+beanObj.getStatusCode()+"##状态信息："+beanObj.getStatusInfo());
                if("200".equals(beanObj.getStatusCode())){
                    ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\result4.pdf"),
                            beanObj.getPdfBty());
                    return R.ok();
                }
                else {
                    return R.error(beanObj.getStatusInfo());
                }
            }
        }
        return null;
    }

    /**
     * 单规则签章
     * @param file
     * @param SingleruleNum
     * @return
     * @throws Exception
     */
    @RequestMapping("/signruleSeal")
public R signruleSeal(@RequestParam("file") MultipartFile file,
                      @RequestParam("SingleruleNum") String SingleruleNum) throws Exception {
    String ruleNum =SingleruleNum;//签章规则编号
    ChannelMessage message = anySignClientTool.pdfSign(ruleNum, file.getBytes());
    System.out.println("状态码："+message.getStatusCode());
    System.out.println("状态信息："+message.getStatusInfo());
    ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\result5.pdf"),message.getBody());
    if(message.getStatusCode().equals("200")){
        return R.ok();
    }  else {
        return R.error(message.getStatusInfo());
    }

}

    /**
     * 多规则签章
     * @param file
     * @param SingleruleNum
     * @param SingleruleNum2
     * @param SingleruleNum3
     * @return
     * @throws Exception
     */
    @RequestMapping("/multiruleSeal")
    public R multiruleSeal(@RequestParam("file") MultipartFile file,
                          @RequestParam("SingleruleNum") String SingleruleNum,
                           @RequestParam("SingleruleNum2") String SingleruleNum2,
                           @RequestParam("SingleruleNum3") String SingleruleNum3) throws Exception {
        String ruleNum =SingleruleNum;//签章规则编号1
        String ruleNum2 =SingleruleNum2;//签章规则编号2
        String ruleNum3 =SingleruleNum3;//签章规则编号3
        List<String> ruleNumList = new ArrayList<String>();
        ruleNumList.add(SingleruleNum);
        if(!SingleruleNum2.equals("")){
            ruleNumList.add(SingleruleNum2);
        }
        if(!SingleruleNum3.equals("")){
            ruleNumList.add(SingleruleNum3);
        }
        ChannelMessage message = anySignClientTool.pdfSign(ruleNumList, file.getBytes());
        System.out.println("状态码："+message.getStatusCode());
        System.out.println("状态信息："+message.getStatusInfo());
        ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\result6.pdf"),message.getBody());
        if(message.getStatusCode().equals("200")){
            return R.ok();
        }  else {
            return R.error(message.getStatusInfo());
        }

    }

    /**
     * 组合签章
     * @param file
     * @param SingleruleNum
     * @param serverSealNumber
     * @param signaturePolicyNumber
     * @return
     * @throws Exception
     */

    @RequestMapping("/CombinationrulesSeal")
    public R CombinationrulesSeal(@RequestParam("file") MultipartFile file,
                           @RequestParam("SingleruleNum") String SingleruleNum,
                                  @RequestParam("Server_seal_number") String serverSealNumber,
                                  @RequestParam("Signature_policy_number") String signaturePolicyNumber) throws Exception {
        String ruleNum =SingleruleNum;//签章规则编号
        String serverSealNum =serverSealNumber;//
        String signPolicyNum =signaturePolicyNumber;//

        System.out.println("服务器印章编号:" + serverSealNumber);
        System.out.println("签名策略编号:" + signaturePolicyNumber);
        List<String> ruleNumList = new ArrayList<String>();
        ruleNumList.add(SingleruleNum);

        ChannelMessage message = anySignClientTool.pdfSign(ruleNum, serverSealNum, signPolicyNum, file.getBytes());
        System.out.println("状态码："+message.getStatusCode());
        System.out.println("状态信息："+message.getStatusInfo());
        ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\result7.pdf"),message.getBody());
        if(message.getStatusCode().equals("200")){
            return R.ok();
        }  else {
            return R.error(message.getStatusInfo());
        }

    }

    /**
     * 高速签章
     * @param file
     * @param SingleruleNum
     * @param SingleruleNum2
     * @param SingleruleNum3
     * @return
     * @throws Exception
     */
    @RequestMapping("/highspeedSeal")
    public R highspeedSeal(@RequestParam("file") MultipartFile file,
                           @RequestParam("SingleruleNum") String SingleruleNum,
                           @RequestParam("SingleruleNum2") String SingleruleNum2,
                           @RequestParam("SingleruleNum3") String SingleruleNum3) throws Exception {
        String ruleNum =SingleruleNum;//签章规则编号1
        String ruleNum2 =SingleruleNum2;//签章规则编号2
        String ruleNum3 =SingleruleNum3;//签章规则编号3
        List<String> ruleNumList = new ArrayList<String>();
        ruleNumList.add(SingleruleNum);
        if(!SingleruleNum2.equals("")){
            ruleNumList.add(SingleruleNum2);
        }
        if(!SingleruleNum3.equals("")){
            ruleNumList.add(SingleruleNum3);
        }
        try {
            ChannelMessage message = anySignClientTool.pdfSpeedSign(ruleNumList, file.getBytes());

            System.out.println("状态码："+message.getStatusCode());
            System.out.println("状态信息："+message.getStatusInfo());
            ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\result8.pdf"),message.getBody());
            if(message.getStatusCode().equals("200")){
                return R.ok();
            }  else {
                return R.error(message.getStatusInfo());
            }

        }catch (Exception e){
           e.printStackTrace();
            System.out.println("888888888888888888");
            return R.error();
        }

    }

    /**
     * 多页签章
     * @param file
     * @param SingleruleNum
     * @return
     * @throws Exception
     */
    @RequestMapping("/multipageSeal")
    public R multipageSeal(@RequestParam("file") MultipartFile file,
                          @RequestParam("SingleruleNum") String SingleruleNum) throws Exception {
        String ruleNum = SingleruleNum;//签章规则编号
        ChannelMessage message = anySignClientTool.pdfMultiPageSign(ruleNum, file.getBytes(),"");
        System.out.println("状态码：" + message.getStatusCode());
        System.out.println("状态信息：" + message.getStatusInfo());
        ClientUtil.writeByteArrayToFile(new File(resourcepath+"Rpdf\\result9.pdf"), message.getBody());
        if (message.getStatusCode().equals("200")) {
            return R.ok();
        } else {
            return R.error(message.getStatusInfo());
        }
    }

    /**
     * 验证pdf签名
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping("/pdfVerify")
    public R pdfVerify(@RequestParam("file") MultipartFile file) throws Exception {

        ChannelMessage message = anySignClientTool.pdfVerify(file.getBytes());
        System.out.println("状态码：" + message.getStatusCode());
        if(message.getStatusCode().equals("200")){
            System.out.println("验证成功");
        }
        System.out.println("状态信息：" + message.getStatusInfo());
        System.out.println("验证结果：" + new String(message.getBody(),"UTF-8"));
        String result=new String(message.getBody(),"UTF-8");
        return R.ok().put("result",result);
    }

    @RequestMapping("/VerifySignplace")
    public R VerifySignplace(@RequestParam("file") MultipartFile file) throws Exception {
        String type = ClientConstant. REQUEST_TYPE_PDFFORMVERIFIY;
        byte[] pdfSignBty = file.getBytes();
        ChannelMessage message = anySignClientTool.pdfFormVerify(pdfSignBty, type);
        System.out.println("状态码：" + message.getStatusCode());
        if(message.getStatusCode().equals("200")){
            System.out.println("验证成功");
        }
        System.out.println("状态信息：" + message.getStatusInfo());
        System.out.println("验证结果：" + new String(message.getBody(),"UTF-8"));
        String result=new String(message.getBody(),"UTF-8");
        return R.ok().put("result",result);
    }


    //========================================================================下载区域=================================================================================
@GetMapping("/downloadpoistionpdf")
public ResponseEntity<byte[]> downloadPDF() throws IOException {
    // Simulated PDF content as a byte array
    byte[] pdfContent = getPDFByteArrayoistion(); // Replace with your actual byte array

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_PDF);
    headers.setContentDispositionFormData("attachment", "test.pdf");

    return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
}

    private byte[] getPDFByteArrayoistion() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\result.pdf");
        return Files.readAllBytes(path);
    }
    @GetMapping("/downloadkeywordpdf")
    public ResponseEntity<byte[]> downloadPDF2() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = getPDFByteArraykeyword(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] getPDFByteArraykeyword() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\result2.pdf");
        return Files.readAllBytes(path);
    }



    @GetMapping("/downloadBaseServeSealnumAndpoistion")
    public ResponseEntity<byte[]> downloadPDF3() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = BaseServeSealnumAndpoistion(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] BaseServeSealnumAndpoistion() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\result3.pdf");
        return Files.readAllBytes(path);
    }


    @GetMapping("/downloadBaseServeSealnumAndkeywordpdf")
    public ResponseEntity<byte[]> downloadPDF4() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadBaseServeSealnumAndkeywordpdf(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadBaseServeSealnumAndkeywordpdf() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\result4.pdf");
        return Files.readAllBytes(path);
    }


    @GetMapping("/downloadsignruleSeal")
    public ResponseEntity<byte[]> downloadPDF5() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadsignruleSeal(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadsignruleSeal() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\result5.pdf");
        return Files.readAllBytes(path);
    }

    @GetMapping("/downloadmultiruleSeal")
    public ResponseEntity<byte[]> downloadPDF6() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadmultiruleSeal(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadmultiruleSeal() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\result6.pdf");
        return Files.readAllBytes(path);
    }

    @GetMapping("/downloadCombinationrulesSeal")
    public ResponseEntity<byte[]> downloadPDF7() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadCombinationrulesSeal(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadCombinationrulesSeal() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\result7.pdf");
        return Files.readAllBytes(path);
    }


    @GetMapping("/downloadhighspeedSeal")
    public ResponseEntity<byte[]> downloadPDF8() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadhighspeedSeal(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadhighspeedSeal() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\result8.pdf");
        return Files.readAllBytes(path);
    }


    @GetMapping("/downloadmultipageSeal")
    public ResponseEntity<byte[]> downloadPDF9() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadmultipageSeal(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadmultipageSeal() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\result9.pdf");
        return Files.readAllBytes(path);
    }

    @GetMapping("/downloadbyMoudelCreateSignPlace")
    public ResponseEntity<byte[]> downloadPDF10() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadbyMoudelCreateSignPlace(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadbyMoudelCreateSignPlace() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\模板产生签名域.pdf");
        return Files.readAllBytes(path);
    }

    @GetMapping("/downloadCreateNullSignPlace")
    public ResponseEntity<byte[]> downloadPDF11() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadCreateNullSignPlace(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadCreateNullSignPlace() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\空签名域.pdf");
        return Files.readAllBytes(path);
    }

    @GetMapping("/downloadwordtoPDFandSeal")
    public ResponseEntity<byte[]> downloadPDF12() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadwordtoPDFandSeal(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadwordtoPDFandSeal() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\Word文档转换PDF插入条形码.pdf");
        return Files.readAllBytes(path);
    }
    @GetMapping("/downloadwordtoPDFandSeal2")
    public ResponseEntity<byte[]> downloadPDF13() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadwordtoPDFandSeal2(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadwordtoPDFandSeal2() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\Word文档转换PDF签章.pdf");
        return Files.readAllBytes(path);
    }


    @GetMapping("/downloadwordProxyClientSignature")
    public ResponseEntity<byte[]> downloadPDF14() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadwordProxyClientSignature(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadwordProxyClientSignature() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\生成代理签章.pdf");
        return Files.readAllBytes(path);
    }

    @GetMapping("/downloadwordcreatBaecodeAndIntoPdf")
    public ResponseEntity<byte[]> downloadPDF15() throws IOException {
        // Simulated PDF content as a byte array
        byte[] pdfContent = downloadwordcreatBaecodeAndIntoPdf(); // Replace with your actual byte array

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_PDF);
        headers.setContentDispositionFormData("attachment", "test.pdf");

        return new ResponseEntity<>(pdfContent, headers, org.springframework.http.HttpStatus.OK);
    }

    private byte[] downloadwordcreatBaecodeAndIntoPdf() throws IOException {
        // Replace this with your logic to get the actual byte array of the PDF file
        // For example, reading from a file using Paths.readAllBytes()
        Path path = Paths.get(resourcepath+"Rpdf\\PDF插入条形码.pdf");
        return Files.readAllBytes(path);
    }

}
